package edu.faytechcc.csc289.gui;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;

/**
 * This class creates the Managers menu
 *
 * Mar 27, 2014
 * @author William Robles
 */
public class ManagementMenu extends JPanel
{

    private final ActionListener bL;

    private JButton salesButton, employeeMgmntButton, inventoryButton,
            exitManagerMenuButton;

    private final Dimension buttonSize = new Dimension(165, 25);

    public ManagementMenu(ActionListener bL)    {
        this.bL = bL;
        this.setLayout(new GridLayout(4, 1));
        this.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED));

        buildButtons();
    }

    /**
     * buildButtons panels creates buttons for main panel
     */
    private void buildButtons()    {
        JPanel temp = new JPanel();

        exitManagerMenuButton = new JButton("Exit");
        exitManagerMenuButton.addActionListener(new ButtonListener());
        exitManagerMenuButton.setPreferredSize(buttonSize);
        inventoryButton = new JButton("Inventory Management");
        inventoryButton.addActionListener(bL);
        inventoryButton.setPreferredSize(buttonSize);
        salesButton = new JButton("Sales");
        salesButton.addActionListener(bL);
        salesButton.setPreferredSize(buttonSize);
        employeeMgmntButton = new JButton("Employee Management");
        employeeMgmntButton.addActionListener(bL);
        
        temp.add(salesButton);
        this.add(temp);
        temp = new JPanel();
        temp.add(employeeMgmntButton);
        this.add(temp);
        temp = new JPanel();
        temp.add(inventoryButton);
        this.add(temp);
        temp = new JPanel();
        temp.add(exitManagerMenuButton);
        this.add(temp);
    }
    
    /**
     * exitFrame method closes frame and launches login
     * @param e actionevent
     */
    private void exitFrame(ActionEvent e)    {
        Component c = (Component) e.getSource();

        JFrame frame = (JFrame) SwingUtilities.getRoot(c);

        frame.dispose();
        MainFrame mf = new MainFrame();
        mf.addMouseListener(new MouseActions());
        mf.addMouseMotionListener(new MouseActions());
    }

    private class ButtonListener implements ActionListener
    {
        public ButtonListener()
        {
        }

        @Override
        public void actionPerformed(ActionEvent ae)
        {
            exitFrame(ae);
        }
    }
}
